package com.gy.api.video.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.gy.api.base.ApiIndex;
import com.gy.api.base.Constants;
import com.gy.api.base.R;
import com.gy.api.common.file.domain.vo.FileVO;
import com.gy.api.mobile.company.domain.vo.CompanyLoginResVO;
import com.gy.api.mobile.company.domain.vo.CompanyLoginVO;
import com.gy.api.mobile.company.domain.vo.CompanyVO;
import com.gy.api.mobile.company.service.ICompanyService;
import com.gy.util.BindingResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/video/")
@Api( tags = ApiIndex.UserLoginController)
@Slf4j
public class UserLoginController {
    @Autowired
    private ICompanyService service;


    @ApiOperation("用户登录{目前只允许企业账号登陆}(账号密码都需要加密传入)")
    @PostMapping("/login")
    public R<CompanyLoginResVO> login(@RequestBody CompanyLoginVO companyLoginVO, BindingResult bindingResult) {
        R result= BindingResultUtil.BindingResult(bindingResult);
        if(result.getCode()== Constants.SYS_SUCCESS){
            CompanyLoginResVO userLoginResVO = service.login(companyLoginVO);
            result.setData(userLoginResVO);
        }
        return result;
    }

    @ApiOperation("退出登录")
    @PostMapping("/login_out")
    @SaCheckLogin
    public R loginOut(){
        StpUtil.logout();
        return new R();
    }

    @ApiOperation("查询当前企业信息")
    @GetMapping("/one")
    @SaCheckLogin
    public R<CompanyVO> getOne(){
        CompanyVO userVO=service.getCompanyOne();
        return new R(userVO);
    }




}
